﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using Peter.Sdw.Logic.Dialogs;

namespace Peter.Sdw.View.Dialogs
{
   /// <summary>
   /// Interaction logic for LoginView.xaml
   /// </summary>
   public partial class LoginView
   {
      private LoginModel m_ViewModel;

      /// <summary>
      /// Initializes the login view.
      /// </summary>
      public LoginView ()
      {
         InitializeComponent ();
         this.DataContextChanged += this.OnDataContextChange;
      }

      private void OnDataContextChange (object sender, DependencyPropertyChangedEventArgs e)
      {
         this.DataContextChanged -= this.OnDataContextChange;
         this.m_ViewModel = this.DataContext as LoginModel;
      }

      private void OnKeyPasswordKeyDown (object sender, KeyEventArgs e)
      {
         if ((e.Key == Key.Enter || e.Key == Key.Return) && this.m_ViewModel != null) {
            this.m_ViewModel.OkExecuted (null);
         }
      }

      private void OnPasswordChanged (object sender, RoutedEventArgs e)
      {
         if (this.m_ViewModel != null) {
            this.m_ViewModel.Password = this.PasswordBox.Password;
         }
      }
   }
}
